package com.huawei.translate;

import com.huawei.translate.conifg.Config;
import com.huawei.translate.util.HttpUtil;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class CleanupExpiredTokenJob implements IJob {

    Logger log = Logger.getLogger(CleanupExpiredTokenJob.class);

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            String url = Config.getTranslateApi() + "/api/oauth";
            CloseableHttpResponse response = HttpUtil.sendDelete(url);

            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
                log.info("Cleanup Error!!");
            }
        } catch (Exception e) {
            log.info("Cleanup Exception!!");
        }

    }
}
